WIN32_PROGRAM = ../../CaseEditor.exe
UNIX_PROGRAM = ../../CaseEditor

SOURCE := $(wildcard $(patsubst %,%/*.cpp,src)) 
OBJECTS = $(patsubst %.cpp,%.o,$(SOURCE))
dependencies = 	$(subst .o,.d,$(OBJECTS))

ifndef WXCFG
	WXCFG=wx-config
endif

ifndef NOTDEBUG
	CXXFLAGS+=  -g 
endif

# implementation

.SUFFIXES:	.o .cpp

all:    $(UNIX_PROGRAM)
both: win32 $(UNIX_PROGRAM) docs

docs:
	$(MAKE) -C doc

win32:
	./win32rel.sh


CXXFLAGS+=  -Isrc `xml2-config --cflags` `$(WXCFG) --cxxflags`  -Wall
LIBS+=`$(WXCFG) --libs`  `xml2-config --libs` `wx-config --libs ogl`

BUILDTAG= `date '+%Y-%m-%d %H:%M'`

VERSION=`grep -o -E "[0-9]{1,}.[0-9]{2,}" ../../src/version.h`

ifneq "$(MAKECMDGOALS)" "clean"
  -include $(dependencies)
endif

define make-depend
	@$(CXX) $(CXXFLAGS) -MM -MF $(subst .o,.d,$@)  -MP -MT $2  $1
endef

%.o: %.cpp
	$(call make-depend,$<,$@)
	$(CXX) -c $(CXXFLAGS)  -o  $@ $<

$(UNIX_PROGRAM): $(OBJECTS)
	@echo "#include <string>" >BuildTag.cpp
	@echo "std::string BuildTag=\"$(BUILDTAG)\";">>BuildTag.cpp
	$(CXX) -c BuildTag.cpp -o BuildTag.o
	$(CXX) -o $(UNIX_PROGRAM) $(OBJECTS) BuildTag.o  $(LIBS)
	rm -f BuildTag.*


$(WIN32_PROGRAM):$(OBJECTS)
	@echo  "#include <string>\nstd::string BuildTag=\"$(BUILDTAG)\";">BuildTag.cpp
	@echo document.write\(\"$(BUILDTAG)\"\)\; >JsBuildTag.js 
	$(CXX) -c BuildTag.cpp -o BuildTag.o
	$(CXX) -o $(WIN32_PROGRAM) $(OBJECTS) $(LIBS) BuildTag.o
	rm -f BuildTag.*

clean: 
	rm -f *.o  $(OBJECTS) $(dependencies)

veryclean: clean
	rm -f $(WIN32_PROGRAM) $(UNIX_PROGRAM)

win32ubuntu:
	bash win32rel.sh.ubuntu

